﻿using SUNRPA.CONTROLS.IMPL.domain;
using SUNRPA.CONTROLS.IMPL.util;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace RPAVIEW.views.loginAndRegist {
    /// <summary>
    /// LoginWindow.xaml 的交互逻辑
    /// </summary>
    public partial class RegisterWindow:Window {
        public RegisterWindow() {
            InitializeComponent();
            this.DataContext = new UserInfo();
        }

        private void DragMove(object sender, MouseButtonEventArgs e) {
            this.DragMove();
        }

        private void Register(object sender, RoutedEventArgs e) {
            UserInfo info = (UserInfo)this.DataContext;
            info.password = this.pw.Password;
            HttpUtil httpUtil = HttpUtil.getInstance(SystemUtil.GetAPPConfig("ControlBaseIp") + SystemUtil.GetAPPConfig("UserUri"));
            HttpResponse<object> response = httpUtil.SendPost<object>("/add", info);
            if(response.Code == 500) { 
                MessageBox.Show(response.Msg);
                return;
            } else { 
                MessageBoxResult re = MessageBox.Show("注册成功！现在返回登录界面？","提示",MessageBoxButton.OKCancel, MessageBoxImage.Warning);
                if(re.Equals(MessageBoxResult.OK)) { 
                    ReturnLogin(null, null);
                }
            }
        }

        private void ReturnLogin(object sender, RoutedEventArgs e) {
            LoginWindow lw = new LoginWindow();
            lw.Show();
            this.Close();
        }

        private void CloseWindow(object sender, RoutedEventArgs e) {
             this.Close();
             Application.Current.Shutdown();
        }
    }
}
